home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 747 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.0 KB

  1. Path: gabi-soft.fr!usenet
  2. From: kanze@gabi-soft.fr (J. Kanze)
  3. Newsgroups: comp.std.c
  4. Subject: Re: va_list, function calls.
  5. Date: 15 Apr 1996 08:54:40 GMT
  6. Organization: GABI Software, Sarl.
  7. Message-ID: <KANZE.96Apr15105440@gabi.gabi-soft.fr>
  8. References: <4kdk5v$mn@solutions.solon.com> <4kkk50$h94@usenet.pa.dec.com>
  9. NNTP-Posting-Host: gabi.gabi-soft.fr
  10. In-reply-to: diamond@tbj.dec.com's message of 12 Apr 1996 03:54:08 GMT
  11.  
  12. In article <4kkk50$h94@usenet.pa.dec.com> diamond@tbj.dec.com (Norman
  13. Diamond) writes:
  14.  
  15. |> In article <4kdk5v$mn@solutions.solon.com>, seebs@solutions.solon.com (Peter Seebach) writes:
  16. |> >    void foo(int bar, ...) {
  17. |> >        va_list ap;
  18. |> >        int i;
  19. |> >        va_start(ap, bar);
  20. |> >        for (i = 0; i < bar; ++i)
  21. |> >            baz(&ap);
  22. |> >        va_end(ap);
  23. |> >    }
  24. |> >    void baz(va_list *ap) { printf("%d\n", va_arg(*ap)); }
  25. |> >is this legal?  If not, is there a compelling reason?
  26.  
  27. |> ANSI Classic section 4.8, page 123 lines 12 to 15:  "The object ap may be
  28. |> passed as an argument to another function; if that function invokes the
  29. |> va_arg macro with parameter ap, the value of ap in the calling function
  30. |> is indeterminate and shall be passed to the va_end macro prior to any
  31. |> further reference to ap."
  32.  
  33. |> The standard does not quite say that &ap may be passed, but let's try to
  34. |> pretend that this was an editorial oversight and a TC will permit it.
  35.  
  36. I'm not sure that it was an editorial oversight.  As currently defined,
  37. I *think* that va_list could be an array type.  (It certainly was on
  38. many pre-ISO implementations, and I can see nothing in the wording of
  39. the current standard to prevent it.)
  40.  
  41. If va_list is an array type, then va_arg will be written using the
  42. implicit conversion to pointer, and passing the ap object will in fact
  43. pass the pointer.
  44.  
  45. |> After the first invocation of baz() returns, the value of ap in the
  46. |> calling function is indeterminate.  ap can be passed to va_end, and I
  47. |> think that &ap can probably be computed and passed around, but the value
  48. |> of ap is just as indeterminate in the second invocation of baz() as it
  49. |> was in main() between the two invocations.
  50.  
  51. I suspect that one of the reasons why the value of ap is indeterminate
  52. is that the standard wishes to make it unspecified whether pass by
  53. reference (as with an array type) or pass by value are being used.
  54.  
  55. |> What you really want is a TC to say that if &ap is passed then the value
  56. |> of ap does not become indeterminate.  Ask your national representative to
  57. |> propose this.
  58.  
  59. IMHO, *if* it is legal to pass `&ap' (or more generally, if the results
  60. of the expression `&ap' are defined to have any reasonable value), then
  61. I think that passing them as a parameter must implicitly work.  However,
  62. I'm not convinced that this expression is legal.
  63. -- 
  64. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  65. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  66. Conseils en informatique industrielle --
  67.                             -- Beratung in industrieller Datenverarbeitung
  68.